import 'package:base_flutter/base_flutter.dart';

import '../../../model/medicine_advice_model.dart';
import '../../../net/response/medicine_advice/medicine_handover_list_data.dart';
import '../../../ui/medicine/medicine_handover/add_medicine_handover_page.dart';

class MedicineHandoverListViewModel extends BaseListViewModel<MedicineHandoverListData> {
  MedicineHandoverListViewModel(super.context);

  String? searchName;

  String? roomName;

  String? medicineName;

  String? handleDate;

  String? handleName;

  var model = MedicineAdviceModel();

  @override
  Future<List<MedicineHandoverListData>> requestListData() async {
    return await model.medicineHandoverList(customerNameLike: searchName,bedNoLike: roomName,drugNameLike: medicineName,executorTimeLike: handleDate,executorNameLike: handleName,page: page,rows: pageLength);
  }

  @override
  void onCreated() {
    super.onCreated();
    requestRefresh();
  }

  void chooseHandleDate() {
    var format = [yyyy, '-', mm, '-', dd];
    DatePicker.showDatePicker(context, currentTime: handleDate?.toDate(),
        onConfirm: (date) {
      handleDate = date!.toDateStr(format);
      notifyListeners();
      requestRefresh();
    });
  }

  void resetClick() {
    searchName = null;
    medicineName = null;
    handleDate = null;
    handleName = null;
    roomName = null;
    notifyListeners();
    requestRefresh();
  }

  Future<void> addHandover() async {
    var data = await Go().push(AddMedicineHandoverPage());
    if(data!=null){
      requestRefresh();
    }
  }
}
